home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / share / hplip / base / mfpdtf.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2009-10-28  |  8KB  |  191 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import struct
  5. import cStringIO
  6. from g import *
  7. from codes import *
  8. NEW_PAGE = 1
  9. END_PAGE = 2
  10. NEW_DOCUMENT = 4
  11. END_DOCUMENT = 8
  12. END_STREAM = 16
  13. RESERVED_20 = 32
  14. RESERVED_40 = 64
  15. RESERVED_80 = 128
  16. MFPDTF_RASTER_BITMAP = 0
  17. MFPDTF_RASTER_GRAYMAP = 1
  18. MFPDTF_RASTER_MH = 2
  19. MFPDTF_RASTER_MR = 3
  20. MFPDTF_RASTER_MMR = 4
  21. MFPDTF_RASTER_RGB = 5
  22. MFPDTF_RASTER_YCC411 = 6
  23. MFPDTF_RASTER_JPEG = 7
  24. MFPDTF_RASTER_PCL = 8
  25. MFPDTF_RASTER_NOT = 9
  26. DT_UNKNOWN = 0
  27. DT_FAX_IMAGES = 1
  28. DT_SCANNED_IMAGES = 2
  29. DT_DIAL_STRINGS = 3
  30. DT_DEMO_PAGES = 4
  31. DT_SPEED_DIALS = 5
  32. DT_FAX_LOGS = 6
  33. DT_CFG_PARMS = 7
  34. DT_LANG_STRS = 8
  35. DT_JUNK_FAX_CSIDS = 9
  36. DT_REPORT_STRS = 10
  37. DT_FONTS = 11
  38. DT_TTI_BITMAP = 12
  39. DT_COUNTERS = 13
  40. DT_DEF_PARMS = 14
  41. DT_SCAN_OPTIONS = 15
  42. DT_FW_JOB_TABLE = 17
  43. RT_START_PAGE = 0
  44. RT_RASTER = 1
  45. RT_END_PAGE = 2
  46. FIXED_HEADER_SIZE = 8
  47. IMAGE_VARIANT_HEADER_SIZE = 10
  48. DIAL_STRINGS_VARIANT_HEADER_SIZE = 6
  49. FAX_IMAGE_VARIANT_HEADER_SIZE = 74
  50. SOP_RECORD_SIZE = 36
  51. RASTER_RECORD_SIZE = 4
  52. EOP_RECORD_SIZE = 12
  53. DIAL_STRING_RECORD_SIZE = 51
  54. PAGE_FLAG_NEW_PAGE = 1
  55. PAGE_FLAG_END_PAGE = 2
  56. PAGE_FLAG_NEW_DOC = 4
  57. PAGE_FLAG_END_DOC = 8
  58. PAGE_FLAG_END_STREAM = 16
  59. SRC_UNKNOWN = 0
  60. SRC_HOST = 2
  61. SRC_SCANNER = 5
  62. SRC_HOST_THEN_SCANNER = 6
  63. SRC_SCANNER_THEN_HOST = 7
  64. TTI_NONE = 0
  65. TTI_PREPENDED_TO_IMAGE = 1
  66. TTI_OVERLAYED_ON_IMAGE = 2
  67. MAJOR_VER = 2
  68. MINOR_VER = 0
  69.  
  70. def parseFixedHeader(buffer):
  71.     fmt = '<IHBB'
  72.     (block_len, header_len, data_type, page_flags) = struct.unpack(fmt, buffer[:8])
  73.     page_flags = page_flags & 31
  74.     return (block_len, header_len, data_type, page_flags)
  75.  
  76.  
  77. def parseImageVariantHeader(buffer, data_type):
  78.     if data_type == DT_SCANNED_IMAGES:
  79.         fmt = '<BBHHHH'
  80.         (major_ver, minor_ver, src_pages, copies_per_page, zoom, jpeg_q_factor) = struct.unpack(fmt, buffer[:10])
  81.         return (major_ver, minor_ver, src_pages, copies_per_page, zoom, jpeg_q_factor)
  82.     if data_type == DT_FAX_IMAGES:
  83.         pass
  84.     
  85.  
  86.  
  87. def parseRecord(buffer):
  88.     record_type = struct.unpack('<B', buffer[0])[0]
  89.     if record_type == RT_START_PAGE:
  90.         fmt = '<BBHHHIIIHHIII'
  91.         (id, encoding, page_num, black_ppr, black_bpp, black_rpp, black_hort_dpi, black_vert_dpi, cmy_ppr, cmy_bpp, cmy_rpp, cmy_hort_dpi, cmy_vert_dpi) = struct.unpack(fmt, buffer[:SOP_RECORD_SIZE])
  92.         if not id == record_type:
  93.             raise AssertionError
  94.         return (id, (encoding, page_num, black_ppr, black_bpp, black_rpp, black_hort_dpi, black_vert_dpi, cmy_ppr, cmy_bpp, cmy_rpp, cmy_hort_dpi, cmy_vert_dpi))
  95.     if record_type == RT_RASTER:
  96.         fmt = '<BBH'
  97.         (id, unused, data_size) = struct.unpack(fmt, buffer[:RASTER_RECORD_SIZE])
  98.         if not id == record_type:
  99.             raise AssertionError
  100.         return (id, (unused, data_size))
  101.     if record_type == RT_END_PAGE:
  102.         fmt = '<BBBBII'
  103.         (id, unused1, unused2, unused3, black_rows, cmy_rows) = struct.unpack(fmt, buffer[:EOP_RECORD_SIZE])
  104.         if not id == record_type:
  105.             raise AssertionError
  106.         return (id, (unused1, unused2, unused3, black_rows, cmy_rows))
  107.     log.error('Error: Invalid record type: %d' % record_type)
  108.     raise Error(ERROR_INTERNAL)
  109.  
  110.  
  111. def readChannelToStream(device, channel_id, stream, single_read = True, callback = None):
  112.     (STATE_END, STATE_FIXED_HEADER, STATE_VARIANT_HEADER, STATE_RECORD) = range(4)
  113.     (state, total_bytes, block_remaining, header_remaining, data_remaining) = (1, 0, 0, 0, 0)
  114.     endScan = False
  115.     while state != STATE_END:
  116.         log.debug('**** State %d ****' % state)
  117.         if state == STATE_FIXED_HEADER:
  118.             if endScan:
  119.                 state = STATE_END
  120.                 break
  121.             
  122.             if data_remaining == 0:
  123.                 (fields, data) = device.readChannel(channel_id)
  124.                 data_remaining = len(data)
  125.                 if callback is not None:
  126.                     endScan = callback()
  127.                 
  128.             
  129.             (block_len, header_len, data_type, page_flags) = parseFixedHeader(data)
  130.             block_remaining = block_len - FIXED_HEADER_SIZE
  131.             header_remaining = header_len - FIXED_HEADER_SIZE
  132.             log.debug('Fixed header: (datalen=%d(0x%x),blocklen=%d(0x%x),headerlen=%d(0x%x),datatype=0x%x,pageflags=0x%x)' % (len(data), len(data), block_len, block_len, header_len, header_len, data_type, page_flags))
  133.             data_remaining -= FIXED_HEADER_SIZE
  134.             data = data[FIXED_HEADER_SIZE:]
  135.             state = STATE_RECORD
  136.             log.debug('Data: data=%d,block=%d,header=%d' % (data_remaining, block_remaining, header_remaining))
  137.             if page_flags & PAGE_FLAG_END_STREAM:
  138.                 state = STATE_END
  139.                 break
  140.             
  141.             if header_remaining > 0:
  142.                 state = STATE_VARIANT_HEADER
  143.             
  144.         header_remaining > 0
  145.         None if state == STATE_VARIANT_HEADER else record_type == RT_START_PAGE
  146.     log.debug('Read %d bytes' % total_bytes)
  147.     return endScan
  148.  
  149.  
  150. def buildMFPDTFBlock(data_type, page_flags = 0, send_variant = False, data = None):
  151.     block = cStringIO.StringIO()
  152.     block.write(struct.pack('<I', 0))
  153.     header_len = FIXED_HEADER_SIZE
  154.     if send_variant:
  155.         if data_type == DT_DIAL_STRINGS:
  156.             header_len += DIAL_STRINGS_VARIANT_HEADER_SIZE
  157.         elif data_type == DT_FAX_IMAGES:
  158.             header_len += FAX_IMAGE_VARIANT_HEADER_SIZE
  159.         
  160.     
  161.     block.write(struct.pack('<H', header_len))
  162.     block.write(struct.pack('<B', data_type))
  163.     block.write(struct.pack('<B', page_flags))
  164.     if send_variant:
  165.         if data_type == DT_DIAL_STRINGS:
  166.             block.write(struct.pack('<BB', MAJOR_VER, MINOR_VER))
  167.             block.write(struct.pack('<H', 1))
  168.             block.write(struct.pack('<H', 51))
  169.         elif data_type == DT_FAX_IMAGES:
  170.             block.write(struct.pack('<BB', MAJOR_VER, MINOR_VER))
  171.             block.write(struct.pack('<B', SRC_HOST))
  172.             block.write(struct.pack('<H', 1))
  173.             block.write(struct.pack('<B', TTI_NONE))
  174.             block.write(struct.pack('<I', 0))
  175.             block.write('\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
  176.             block.write('                    ')
  177.             block.write('                    ')
  178.             block.write('<I', 0)
  179.         
  180.     
  181.     if data_type == DT_DIAL_STRINGS:
  182.         if data is not None:
  183.             dial_string = data['dial-string']
  184.             block.write(dial_string)
  185.             block.write('\x00' * (51 - len(dial_string)))
  186.         
  187.     elif data_type == DT_FAX_IMAGES:
  188.         pass
  189.     
  190.  
  191.